package org.ras.controller;

import org.ras.entity.Account;
import org.ras.service.AccountService;
import org.ras.util.Result;
import org.ras.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * Title: Account controller
 * CreateDate:  2018/1/31
 *
 * @author houdengw
 * @version 1.0
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    private static final Logger logger = LoggerFactory.getLogger(AccountController.class);

    @Autowired
    private AccountService accountService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result getAccounts() {
        logger.info("测试demo:获取账号集合");
        return ResultUtil.success(accountService.getAccounts());
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result saveAccount(Account account) {
        Account _account = accountService.saveAccount(account);
        return ResultUtil.success(_account);
    }

    @RequestMapping(value = "/username/{username}", method = RequestMethod.GET)
    public Result getAccountByUsername(@PathVariable String username) {
        return ResultUtil.success(accountService.getAccountByUsername(username));
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Result getAccountById(@PathVariable String id) {
        return ResultUtil.success(accountService.getAccountByUserId(id));
    }
}
